<%@ page import="org.apache.commons.fileupload.FileItem" %>
      <%@ page import="java.util.List" %>
      <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
      <%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
      <%@ page import="org.apache.commons.io.FilenameUtils" %>
      <%@ page import="java.io.*" %>
      <%@ page contentType="text/html;charset=GB2312" language="java"%>
<%


String redirectURL ="postUpBsonReceived.brl";
String accmonth = "";

try {

    if (ServletFileUpload.isMultipartContent(request)) {
	
	ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
	List<FileItem> fileItemsList = servletFileUpload.parseRequest(request);

	for (FileItem item : fileItemsList) {
	    if (item.isFormField() && item.getFieldName().compareTo("accmonth")==0) 
		accmonth = item.getString();
	}

	for (FileItem item : fileItemsList) {
	    if (!item.isFormField()) {
		String clientPath = "papers/bsoncash" + accmonth+".xls"; 
		File file = new File(application.getRealPath(clientPath));
		if (!file.getParentFile().exists()) {
		    file.getParentFile().mkdirs();
		}
		System.out.println(file.toString());

		item.write(file);
		// response.sendRedirect("./driveTimeDBJob.brl");

	    }
	}
    }
//    PrintWriter writer = response.getWriter();
//    writer.write(" multipartOk");

    redirectURL += "?accmonth=";
    redirectURL += accmonth;
} catch (Exception ee){
    System.out.println(ee.toString());
    redirectURL += "error=";
    redirectURL += ee.toString();
} finally {
    System.out.println(redirectURL);
//    response.sendRedirect(redirectURL);
    
}

%>

